package com.example.juc;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestState {
    public static void main(String[] args) {
        Thread t1 = new Thread("t1"){
            @Override
            public void run() {
                log.debug("running");//new
            }
        };

        Thread t2 = new Thread("t2"){//runnable
            @Override
            public void run() {
                while(true){

                }
            }
        };
        t2.start();

        Thread t3 = new Thread("t3"){//terminated
            @Override
            public void run() {
                log.debug("running3");
            }
        };
        t3.start();

        Thread t4 = new Thread("t4"){
            @Override
            public void run() {
                synchronized (TestState.class){
                    try {
                        Thread.sleep(1000000);//timed_waiting
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t4.start();

        Thread t5 = new Thread("t5"){//waiting
            @Override
            public void run() {
                try {
                    t2.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        t5.start();

        Thread t6 = new Thread("t6"){//blocked
            @Override
            public void run() {
                synchronized (TestState.class){//t4已经加锁了，导致无法锁类
                    try {
                        Thread.sleep(1000000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t6.start();

        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        log.debug(String.valueOf(t1.getState()));
        log.debug(String.valueOf(t2.getState()));
        log.debug(String.valueOf(t3.getState()));
        log.debug(String.valueOf(t4.getState()));
        log.debug(String.valueOf(t5.getState()));
        log.debug(String.valueOf(t6.getState()));
    }
}
